package org.example.struct.array2;

import java.util.Arrays;

/**
 * @author liyishan
 * @date 2024/9/10 10:54
 * @apiNote
 */

public class Test01423MaxScore {
    public int maxScore(int[] cardPoints, int k) {
        int n = cardPoints.length;
        int sum = 0;
        for(int i =0; i< n-k; i++){
            sum += cardPoints[i];
        }
        int minSum = sum;
        for(int i = n-k;i<n;i++){
            sum += cardPoints[i] -cardPoints[i-n+k];
            minSum = Math.min(minSum,sum);
        }
        return Arrays.stream(cardPoints).sum()-minSum;
    }
}
